<?php
class about_model extends CI_Model {
	
	function __construct ()
	{
		parent::__construct();	
	}
	
	function count_list()
	{
		$this->db->where('active',1);
		$query = $this->db->get('gioi_thieu');
		return $query->num_rows();
	}
	
	function get_list($num, $offset)
	{
		$this->db->where('active',1);
		$this->db->order_by('datepost','DESC');
		$query = $this->db->get('gioi_thieu');
		return $query->result();
	}
	function save()
	{
          $id = (int)$this->uri->segment(3);
          $data = array(
            'title_vn' => (string)$this->input->post('subject_vn'),
            'title_us' => strtolower(stringchange($this->input->post('subject_vn'))),
            'images' => (string)$this->input->post('ks_image'),
            'subcontent_vn' => (string)$this->input->post('subcontent_vn'),
            'contens_vn' => (string)$this->input->post('content_vn'),
            'active' => (int)$this->input->post('status'),
            'datepost' => date("Y-m-d H:i:s")
          );
          if($id!=0){
              $this->db->where('gt_id',$id);
              if($this->db->update('gioi_thieu',$data)){
                  return true;
              }else{
                  return false;
              }
		}else{
              if($this->db->insert('gioi_thieu',$data)){
                  return true;
              }else{
                  return false;
              }
          }
	}

	function getabout($id)
	{
		$this->db->where('gt_id',$id);
		$query = $this->db->get('gioi_thieu');
		return $query->row();
	}
	
	function delete($id)
	{
		$data = array('active' => -1);
		$this->db->where('gt_id',$id);
		if($this->db->update('gioi_thieu', $data)){
		  return true;
		}else{
		  return false;
		}
	}
	
      function delsabout($id)
	  {
          $this->db->where('gt_id',$id);             
		  if($this->db->delete('about')){
			  return true;
		  }else{
			  return false;
		  }
      }

}
?>